#include <vector>
#include <algorithm>

using namespace std;

class Solution
{
public:
    int maxSubArray(vector<int> &nums)
    {
        int ret = nums[0];
        int sum = 0;
        for (int i = 0; i < nums.size(); ++i)
        {
            sum = max(sum + nums[i], nums[i]);
            ret = max(sum, ret);
        }
        return ret;
    }
};